package com.yowasa.xiuxian.engine.battle.strategy.drop.all;

import cn.hutool.core.util.NumberUtil;
import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.engine.battle.strategy.BaseSpellStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@BS(name = "如狼的狩猎")
@Order(502)
@Component
public class RuLangShouLie extends BaseSpellStrategy {
    @Autowired
    private BattleHelper battleHelper;

    @Override
    public ElementEnum getElement() {
        return null;
    }

    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {
        int orgAtk = first.getBattleInfo().getAtk();
        double div = NumberUtil.div(second.getBattleInfo().getChp(), second.getBattleInfo().getHp());
        double v = 2 * (1 - div);
        v = v > 1.4 ? 1.5 : v;
        int def = second.getBattleInfo().getDef();
        int dmg = (int) (battleHelper.calAtk(orgAtk, def) * (v+1.5));
        battleHelper.autoAction(this, first, second, content, dmg, "如狼的狩猎");
        first.getCd().put("如狼的狩猎", 4);

    }

    @Override
    public void limit(UserBO user) {
        throw new HandlerException("该战技无法直接学习，需要拥有 武器-[狼的末路] ，装备在身上时自动学会");

    }

    @Override
    public String limitDesc() {
        return "学习/使用如狼的狩猎需要拥有 武器-[狼的末路] ";
    }

    @Override
    public String desc() {
        return "不灭的狼灵随你一同征战，孤狼是身上总是染血\n骑士挥舞重剑，狼灵也一同出击，随着对方生命值的降低你造成的伤害也逐渐提高\n" +
                "造成1.5-3倍的物理伤害，对面生命低于30%时获得最大加成，cd 4回合";
    }
    @Override
    public boolean check(UserBattleContent user, BattleContent content) {
        Integer cd = user.getCd().get("如狼的狩猎");
        if (cd != null && cd > 0) {
            return false;
        }
        return true;
    }
}
